<!-- Vue template -->
<template>
  <div>
    <PureTableBar title="任务明细" class="h100">
      <template #buttons>
        <p class="text-red-500 absolute left-[120px] leading-7 text-sm">注：双击查看详情</p>
        <el-button type="primary" :icon="useRenderIcon(AddFill)" @click="DetailsUpdate(undefined)">
          添加任务明细
        </el-button>
      </template>
      <template v-slot="{ size, checkList }">
        <pure-table border align-whole="center" showOverflowTooltip table-layout="auto" :loading="loading" size="small"
          :data="dataList" :columns="columns" :checkList="checkList" :pagination="pagination" max-height="350"
          :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }" @size-change="handleSizeChange" @current-change="handleCurrentChange" @cell-dblclick="DetailsUpdate">
          <template #operation="{ row }">
            <el-button class="reset-margin" link type="primary" :size="size" :icon="useRenderIcon(EditPen)"
              @click="DetailsUpdate(row)" :disabled="row.isTemplate ? !(row.isEdit == 1) : false">
              修改
            </el-button>
            <el-button class="reset-margin" link type="danger" @click="handleDelete(row)" :size="size"
              :icon="useRenderIcon(Delete)" :disabled="row.isTemplate ? !(row.isDelete == 1) : false">
              删除
            </el-button>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
    <!-- 明细管理 loading -->
    <el-dialog @close="ClosePanelVisible(UpedateRef)" v-model="updatePanelVisible" top="5vh" :close-on-click-modal="false"
      :title="loadingTitle" width="45%" style="min-width: 600px" center destroy-on-close>
      <el-form label-position="right" ref="UpedateRef" :rules="rules" label-width="100px" :model="forms">
        <el-form-item label="操作菜单" prop="submoduleId">
          <el-select placeholder="请选择" filterable v-model="forms.submoduleId" :disabled="_disabled"
            value-key="submoduleName" @change="GetTaskDetailKeywords_submoduleId" class="w-192">
            <el-option v-for="plan in modelItemList" :key="plan.entityId" :label="plan.submoduleName" :value="plan" />
          </el-select>
        </el-form-item>
        <el-form-item label="分值" prop="score">
          <el-input type="number" v-model="forms.score" @blur="handleInput" class="w-192" />
        </el-form-item>
        <el-form-item label="关键词设定" prop="taskKeywrodList">
          <el-scrollbar height="400px">
            <CreditTable v-if="showForm" :value="GetTaskDetailKeywordForm" :lable="GetTaskAllDetailKeywordsForm" />
            <my-table v-if="showTable" :value="GetTaskDetailKeywordTable" :lable="GetTaskAllDetailKeywordsTable" />
            <p v-if='showNoOperation' style="font-size: 20px;color: red;">没有关键字，操作便可以得分!</p>
          </el-scrollbar>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" :loading="loading" @click="updateTask(UpedateRef)"
            :disabled="forms.isTemplate ? !(forms.isEdit == 1) : false">
            保存
          </el-button>
          <el-button @click="ClosePanelVisible(UpedateRef)">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup>
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { useDetail } from "./hook";
import MyTable from "./compoment/table.vue";
import CreditTable from "./compoment/CreditTable.vue";
import EditPen from "@iconify-icons/ep/edit-pen";
import AddFill from "@iconify-icons/ri/add-circle-line";
import Delete from "@iconify-icons/ep/delete";
const {
  rules,
  forms,
  columns,
  loading,
  dataList,
  _disabled,
  pagination,
  UpedateRef,
  showTable,
  showForm,
  showNoOperation,
  loadingTitle,
  modelItemList,
  updatePanelVisible,
  GetTaskDetailKeywordForm,
  GetTaskDetailKeywordTable,
  GetTaskAllDetailKeywordsForm,
  GetTaskAllDetailKeywordsTable,
  noKeywords,
  GetTaskDetailKeywords_submoduleId,
  handleCurrentChange,
  ClosePanelVisible,
  handleSizeChange,
  DetailsUpdate,
  handleDelete,
  updateTask,
  handleInput
} = useDetail();
</script>
<style lang="scss" scoped>
:deep(.el-scrollbar) {
  width: 100%;
}

:deep(.el-form-item__label) {
  font-weight: 700
}

.h100 {
  .pure-table {
    height: calc(100% - 60px);

    :deep(.el-table--fit) {
      height: calc(100% - 60px);
    }
  }
}
</style>
